package com.bwie.controller;

import com.bwie.utils.Result;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Currency;
import java.util.Locale;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2025/5/26 21:12
 */

@RestController
@RequestMapping("/shop/bigdecimal")
public class BigDecimalController {

    @PostMapping("/addBig/{a}/{b}")
    public Result addBig(@PathVariable("a")BigDecimal a, @PathVariable("b")BigDecimal b) {
        BigDecimal c = a.add(b);
        return Result.ok().setData(c);
    }

    @PostMapping("/subBig/{a}/{b}")
    public Result subBig(@PathVariable("a")BigDecimal a, @PathVariable("b")BigDecimal b) {
        BigDecimal c = a.subtract(b);
        return Result.ok().setData(c);
    }

    @PostMapping("/mulBig/{a}/{b}")
    public Result mulBig(@PathVariable("a")BigDecimal a, @PathVariable("b")BigDecimal b) {
        BigDecimal c = a.multiply(b);
        return Result.ok().setData(c);
    }

    @PostMapping("/divBig/{a}/{b}")
    public Result divBig(@PathVariable("a")BigDecimal a, @PathVariable("b")BigDecimal b) {
        BigDecimal c = a.divide(b);
        return Result.ok().setData(c);
    }



    @PostMapping("/mulBigInteger/{a}/{b}")
    public Result mulBigInteger(@PathVariable("a")BigDecimal a, @PathVariable("b") Integer b) {
        BigDecimal c = a.multiply(new BigDecimal(b));
        return Result.ok().setData(c);
    }

    @PostMapping("/roundBig1/{a}/{b}")
    public Result roundBig1(@PathVariable("a")BigDecimal a) {
        BigDecimal bigDecimal = a.setScale(0, BigDecimal.ROUND_HALF_UP);
        return Result.ok().setData(bigDecimal);
    }

    @PostMapping("/roundBig2/{a}/{b}")
    public Result roundBig2(@PathVariable("a")BigDecimal a) {
        BigDecimal bigDecimal = a.setScale(2, BigDecimal.ROUND_HALF_UP);
        return Result.ok().setData(bigDecimal);
    }

    @PostMapping("/roundBig3/{a}/{b}")
    public Result roundBig3(@PathVariable("a")BigDecimal a) {
        BigDecimal bigDecimal = a.setScale(4, BigDecimal.ROUND_HALF_DOWN);
        return Result.ok().setData(bigDecimal);
    }

    @PostMapping("/roundBig4/{a}/{b}")
    public Result roundBig4(@PathVariable("a")BigDecimal a) {
        BigDecimal bigDecimal = a.setScale(3, BigDecimal.ROUND_UP);
        return Result.ok().setData(bigDecimal);
    }

    @PostMapping("/roundBig5/{a}/{b}")
    public Result roundBig5(@PathVariable("a")BigDecimal a) {
        BigDecimal bigDecimal = a.setScale(1, BigDecimal.ROUND_DOWN);
        return Result.ok().setData(bigDecimal);
    }

    @PostMapping("/roundBig6/{a}")
    public Result roundBig6(@PathVariable("a") BigDecimal a) {
        BigDecimal amount = a;

        // 美元
        // Locale.US
        // 欧元
        //Locale.GERMANY
//        Locale.GERMANY

        // 指定特定货币代码:日元
        NumberFormat jpyFormat = NumberFormat.getCurrencyInstance(Locale.GERMANY);
        jpyFormat.setCurrency(Currency.getInstance("EUR"));
        String format = jpyFormat.format(amount);// 输出: ￥1,234,568
        return Result.ok().setData(format);
    }
}
